<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>

        let who = 'foo';

        let greeting = `Hello ${who} World!`;

        console.log(greeting)

        let students = [
            {
                name: '张三',
                age: 20
            },
            {
                name: '张三',
                age: 20
            },
            {
                name: '张三',
                age: 20
            }
        ];

        // let htmls = ''

        // students.forEach(function (student) {
        //     // htmls += '<tr><td>'+ student.name +'</td><td>'+ student.age +'</td></tr>'
        //     htmls += `<tr>
        //         <td>${student.name}</td>
        //         <td>${student.age}</td>
        //     </tr>`;
        // })

        // console.log(htmls)


        // 补充内容，数组对象 reduce() 方法的使用
        let htmls = students.reduce(function (htmls, student){
            return htmls + `<li>${student.name}</li>`
        }, '')

        console.log(htmls)

        // '' + 'li'

        // 'li' + 'li'

        // 'li' + 'li' + 'li'


        let numbers = [1, 23, 45, 21]

        let sum = numbers.reduce(function (total, num) {
            return total + num
        }, 0)

        console.log(sum)

    </script>
</body>
</html>